// ActionScript file
import com.helloniu.data.wb.WBStyle;
import com.helloniu.data.wb.RectStyle;
import com.helloniu.fl.util.StyleTool;
import com.helloniu.fl.util.Tool;

private var lineWidthArr:Array = [
	{label:"1", data:1},
	{label:"3", data:3},
	{label:"5", data:5}
	];

private var rectStyle:RectStyle = new RectStyle();
private var rectStyle2:RectStyle = new RectStyle();

private function initComp(e:*):void {
    StyleTool.setBtnStyle(applyBtn, "applyIcon");

    lineWidthCombo.dataProvider = lineWidthArr;
}


public function populate():void {
    lineWidthCombo.selectedIndex = ((rectStyle.lineWidth - 1)/2 as int);

    lineColor.selectedColor = rectStyle.lineColor.color;
    lineAlpha.text = "" + (rectStyle.lineColor.alpha*100 as int);

    fillColor.selectedColor = rectStyle.fillColor.color;
    fillAlpha.text = "" + (rectStyle.fillColor.alpha*100 as int);
}

public function update():void {
    rectStyle2.lineWidth = lineWidthCombo.selectedItem.data;

    rectStyle2.lineColor.color = lineColor.selectedColor;
    rectStyle2.lineColor.alpha = Tool.toAlpha(parseInt(lineAlpha.text));//0~1? 0~~100??

    rectStyle2.fillColor.color = fillColor.selectedColor;
    rectStyle2.fillColor.alpha = Tool.toAlpha(parseInt(fillAlpha.text));//0~1? 0~~100??

    // @temp tonyy, event
    // fire ModifyEvent()
}

public function getWBStyle():WBStyle {
	update();

	return rectStyle2;
}

public function setWBStyle(awbstyle:WBStyle):void {
	rectStyle = awbstyle as RectStyle;
}

override protected function updateDisplayList(w:Number, h:Number):void {
	super.updateDisplayList(w, h);
	
	if(w > 0 && h > 0) {
		populate();
	}	
}